﻿Imports System.Data.OleDb
Public Class Ratings
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bt_SubmitRatings.Click
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("Phones").ConnectionString)
        oleDbConn.Open()
        Dim delRatingSql As String = "DELETE From Ratings WHERE PhonesID AND UserName =@f3"
        Dim delRatingsCmd As OleDbCommand = New OleDbCommand(delRatingSql, oleDbConn)
        delRatingsCmd.Parameters.AddWithValue("@f1", Request.Params("ID"))
        delRatingsCmd.Parameters.AddWithValue("@f2", User.Identity.Name)
        delRatingsCmd.ExecuteNonQuery()

        Dim Sql = "INSERT into Ratings (PhonesID,UserName,Rating) VALUES (@f1,@f2,@f3)"
        Dim addRatingsCmd As OleDbCommand = New OleDbCommand(Sql, oleDbConn)
        addRatingsCmd.Parameters.AddWithValue("@f1", Request.Params("ID"))
        addRatingsCmd.Parameters.AddWithValue("@f2", User.Identity.Name)
        addRatingsCmd.Parameters.AddWithValue("@f3", Rating1.CurrentRating)
        addRatingsCmd.ExecuteNonQuery()
        lb_Ratings.Text = "Thanks you for adding your ratings"
    End Sub
End Class